//
//  ZZHForTD_UPLoadingShowView.m
//  GJProgressView
//
//  Created by Star J on 2018/4/28.
//  Copyright © 2018年 GJ. All rights reserved.
//

#import "ZZHForTD_UPLoadingShowView.h"
#import "ZZHForTD_UPLoadingView.h"

#define DEFAULTSIZE 75.f
#define SELFSIZE self.frame.size

@interface ZZHForTD_UPLoadingShowView()

@property (nonatomic , strong)ZZHForTD_UPLoadingView *PathView;


@end


@implementation ZZHForTD_UPLoadingShowView

ZZHForTD_UPLoadingShowView *g_instance_self;
+(instancetype)ShareView{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if(g_instance_self==nil){
            g_instance_self = [[ZZHForTD_UPLoadingShowView alloc]init];
        }
    });
    return g_instance_self;
}


-(void)Created_self{
//    dispatch_async(dispatch_get_main_queue(), ^{
        g_instance_self.frame = [UIScreen mainScreen].bounds;
        g_instance_self.backgroundColor = RGBA(0, 0, 0, 0.3);
        g_instance_self.userInteractionEnabled = YES;
        [g_instance_self addSubview:g_instance_self.PathView];
        self.PathView.strokelineWidth = 5;
        [self.PathView set_Progress:0];
        [[UIApplication sharedApplication].keyWindow addSubview:g_instance_self];
    //a
//    });
}

-(void)setProgress:(CGFloat)progress{
//    NSLog(@"progress --- %f",progress);
    
    //
    [UIView animateWithDuration:2 animations:^{
        [self.PathView set_Progress:progress*100];
    }];
}

-(void)setText_defaultText:(NSString*)defaultText andPageText:(NSString*)PageText{
    [self.PathView setText_defaultText:defaultText andPageText:PageText];
}



//懒加载
-(UIView*)PathView{
    if(!_PathView){
        _PathView = [[ZZHForTD_UPLoadingView alloc]initWithFrame:CGRectMake(SELFSIZE.width/2 - DEFAULTSIZE/2, SELFSIZE.height/2 - DEFAULTSIZE/2, DEFAULTSIZE, DEFAULTSIZE)];
    }
    return _PathView;
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"remove");
//    [g_instance_self removeFromSuperview];
    
}

-(void)removeSelf{
    [g_instance_self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
